package com.nuoniu.sibanyun.service.crm.call.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nuoniu.sibanyun.common.exception.NuoNiuException;
import com.nuoniu.sibanyun.entity.crm.call.CrmCallNumberPool;
import com.nuoniu.sibanyun.entity.crm.call.dto.CrmCallNumberPoolSearchDto;
import com.nuoniu.sibanyun.mapper.crm.call.CrmCallNumberPoolMapper;
import com.nuoniu.sibanyun.service.crm.call.ICrmCallAgentService;
import com.nuoniu.sibanyun.service.crm.call.ICrmCallNumberPoolService;
import com.nuoniu.sibanyun.userThread.UserInfo;
import com.nuoniu.sibanyun.userThread.UserThreadLocal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 客户系统-线路管理（资费） 服务实现类
 * </p>
 *
 * @author 白强
 * @since 2022-04-15
 */
@Service
public class CrmCallNumberPoolServiceImpl extends ServiceImpl<CrmCallNumberPoolMapper, CrmCallNumberPool> implements ICrmCallNumberPoolService {

    @Autowired
    private ICrmCallAgentService callAgentService;

    @Override
    public Page<CrmCallNumberPool> pageCrmCallNumberPool(CrmCallNumberPoolSearchDto crmCallNumberPoolSearchDto) {
        Page<CrmCallNumberPool> crmCallNumberPoolPage = baseMapper.pageCrmCallNumberPool(crmCallNumberPoolSearchDto.getPage(), crmCallNumberPoolSearchDto);
        return crmCallNumberPoolPage;
    }

    @Override
    public void saveCrmCallNumberPool(CrmCallNumberPool crmCallNumberPool) {
        UserInfo userInfo = UserThreadLocal.get();
        Long id = crmCallNumberPool.getId();
        if(null == id){
            crmCallNumberPool.setCreateUserId(userInfo.getUserId());
            crmCallNumberPool.setCreateUserName(userInfo.getRealName());
            crmCallNumberPool.setCreateDate(LocalDateTime.now());
        }
        saveOrUpdate(crmCallNumberPool);
    }

    @Override
    public void batchDelete(List<Long> ids) {
        removeByIds(ids);
    }
}
